﻿using AFanDa.BLL.BLLService;
using AFanDa.Dto.Request;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace AFanDa.Api.Controllers
{
    public class CardController : ApiController
    {
        private readonly CardService _cardService = null;

        /// <summary>
        /// 
        /// </summary>
        public CardController()
        {
            _cardService = new CardService();
        }

        /// <summary>
        /// 新增卡券
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public IHttpActionResult AddCard(CardRequestDto dto)
        {
            var result = _cardService.AddCard(dto);
            return Ok(result);
        }




        /// <summary>
        /// 获取卡券列表
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpGet]
        public IHttpActionResult GetCards(int page = 1, int limit = 10, string key = "")
        {
            var result = _cardService.GetCards(new CardRequestDto()
            {
                page = page,
                limit = limit,
                key = key ?? ""
            });
            return Ok(result);
        }

        /// <summary>
        /// 获取单张卡券
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public IHttpActionResult GetSingleCard(string id)
        {
            var result = _cardService.GetSingleCard(new CardRequestDto()
            {
                id = id
            });
            return Ok(result);
        }


        /// <summary>
        /// 领取优惠券：PS:该方法应该只存在一个参数 期中UID参数应该有后台通过token获取
        /// </summary>
        /// <param name="cid"></param>
        /// <param name="uid"></param>
        /// <returns></returns>
        [HttpGet]
        public IHttpActionResult GainCard(string cid, string uid)
        {
            var result = _cardService.GainCard(new CardRequestDto()
            {
                id = cid,
                uid = uid
            });
            return Ok(result);
        }

    }
}
